/**************************************************************
  > File Name: 76.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年02月11日 星期五 14时41分53秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * minWindow(char * s, char * t)
{
	int *visted = calloc(58, sizeof(int));
	int i;
	int left = 0;
    int right = 0;
	int minstart = 0;
	int slen = strlen(s);
	int tlen = strlen(t);
	int min = slen + 1;
	
	for (i = 0; i < tlen; i++)
	{
		visted[t[i]-'A'] += 1;
	}

	while (right < slen)
	{
		if (visted[s[right]-'A']-- > 0)	
		{
			tlen--;
		}
		right++;

		while (tlen == 0)
		{
			if (right - left < min)
			{
				minstart = left;
				min = right - left;
			}
			visted[s[left]-'A']++;
			if (visted[s[left]-'A'] > 0)
			{
				tlen++;
			}
			left++;
		}
	}
	if (min != slen + 1)
	{
		s[minstart+min] = '\0';
		return s + minstart;
	}
	return "";
}

int main(int argc, char **argv)
{
	char s[] = "cabwefgewcwaefgcf";
	char t[] = "cae";
	char *ret = NULL;

	ret = minWindow(s, t);
	puts(ret);

    exit(0);
}
